﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using CompanyBussiness;

namespace Website.customer.Control
{
    public partial class cDetailProduct : System.Web.UI.UserControl
    {
        ProductManagement proMana = new ProductManagement();
        LanguagesManagement languageMana = new LanguagesManagement();
        CompanyBussiness.Product pro = new Product();
        CompanyBussiness.Language language;
        int productIDs;
        string modulCode;
        HtmlMeta metaTag;
        NewsManagement newsMana = new NewsManagement();
        CompanyBussiness.New news = new New();
        Metadata meta;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request[CONST.QUERYSTRING_PRODUCT] == null)
                {
                    //quay ve trang home
                    Response.Redirect("~/Hem.html");
                }
                else
                {
                    LoadContent();
                }
            }
        }
        protected void LoadContent()
        {
            try
            {
                productIDs = int.Parse(Request[CONST.QUERYSTRING_PRODUCT].ToString());
                pro = proMana.GetProductByID(productIDs);

                lbSubject.Text = pro.ProductName;
                if (pro.ProductImg != string.Empty)
                {
                    imgNews.ImageUrl = pro.ProductImg.Replace("img_", "larger_");
                    imgNews.ToolTip = pro.ProductName;
                }
                
                //litContent.Text = pro.ProductDes;
                lbContent.InnerHtml = pro.ProductDes;
                lbDate.Text = pro.ProductCode;

                meta = newsMana.GetMetadataByProductID(productIDs);
                if (meta != null)
                {
                    //Page.Header.Controls.Clear();


                    //ghi metadata
                    metaTag = new HtmlMeta();
                    metaTag.Name = "keywords";
                    metaTag.Content = meta.MetaKeyword;
                    Page.Header.Controls.Add(metaTag);

                    metaTag = new HtmlMeta();
                    metaTag.Name = "description";
                    metaTag.Content = meta.MetaDesciption;
                    Page.Header.Controls.Add(metaTag);

                    Page.Header.Title = meta.Title;
                }
            }
            catch (Exception)
            {

            }
        }
    }
}